package com.briup.facade.web.controller;

import com.briup.common.web.Message;
import com.briup.common.web.MessageUtil;
import com.briup.facade.service.IFascadeEvaluateService;
import com.briup.logging.annotation.LoggingAccess;
import com.briup.model.service.IEvaluateService;
import com.briup.model.vo.EvaluateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@LoggingAccess("评估模块")
@Api(tags = "评估模块")
@RestController
@RequestMapping("/evaluate")
public class EvaluateController {

    @Autowired
    private IEvaluateService evaluateService;
    @Autowired
    private IFascadeEvaluateService fascadeEvaluateService;

    // 获取最新训练所用数据集情况
    @LoggingAccess("获取最新训练所用数据集分类")
    @ApiOperation(value = "获取最新训练所用数据集分类", notes = "参数类型为resultful模板")
    @GetMapping("/{modelId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelId", value = "模型id", paramType = "path", dataType = "int", required = true)
    })
    public Message findClassifysInTraning(@PathVariable("modelId") Integer modelId) {
        // 如果有现成数据集,返回数据集id,没有就返回最新训练所用的分类名称和分类数量
        Map<String,Object> map = fascadeEvaluateService.findClassifysInTraning(modelId);

        return MessageUtil.success(map);
    }

    // 模型评估
    @LoggingAccess("模型评估")
    @ApiOperation(value = "模型评估", notes = "参数类型为json+resultful模板")
    @PostMapping("/{modelId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelId", value = "模型id", paramType = "path", dataType = "int", required = true)
    })
    public Message evaluateTraining(@RequestBody EvaluateVo evaluateVo,
                                    @PathVariable("modelId") Integer modelId) {

        fascadeEvaluateService.evaluateTraining(evaluateVo,modelId);
        return MessageUtil.success("已提交模型评估,请等待评估结果");
    }

}
